package hotelManagement.reserve;
import org.springframework.orm.hibernate3.support.*;
import org.hibernate.Hibernate;
import java.util.*;

public class ReserveInfoDaoImpl extends HibernateDaoSupport implements ReserveInfoDao{
	public ReserveInfo get(String reserveid){
		ReserveInfo ri=(ReserveInfo)getHibernateTemplate().get(ReserveInfo.class, reserveid);
		return ri;
	}
	
	public void save(ReserveInfo reserveInfo){
		getHibernateTemplate().save(reserveInfo);
	}
	
	public void delete(ReserveInfo reserveInfo){
		getHibernateTemplate().delete(reserveInfo);
	}
	
	public void delete(String reserveid){
		getHibernateTemplate().delete(get(reserveid));
	}
	
	public void update(ReserveInfo reserveInfo){
		getHibernateTemplate().update(reserveInfo);
	}
	
	public List<ReserveInfo> getAll(){
		return getHibernateTemplate().find("from ReserveInfo");
	}
	
	public ReserveInfo getByRoomNumberAndCheckInTime(String roomNumber, String checkInTime){
		List<ReserveInfo> reserveInfo = getHibernateTemplate().find(
				"from ReserveInfo as r where r.roomNumber='" + roomNumber + "' and r.checkInTime='" + checkInTime + "'");
		return reserveInfo != null ? reserveInfo.get(0) : null;
	}
	public List<ReserveInfo> getByPersonId(String personid){
		List<ReserveInfo> reserveInfo = getHibernateTemplate().find(
				"from ReserveInfo as r where r.personId='" + personid +"'"	);
		return reserveInfo;
	}
	
}
